﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DeviceManager
{
    class VideoDumpper
    {
        static string FormatMap = "FormatMap";
        static string DataMap = "DataMap";
        
        public static long DataMapLength = 1024 * 1024 * 32;
        public static int HeaderLength = 2048;


        FileMapping m_FormatMap;
        FileMapping m_DataMap;
        int m_PosWrite = 0;
        public void Init()
        {
            m_FormatMap = new FileMapping();
            m_FormatMap.Init(FormatMap, HeaderLength + 8);

            m_DataMap = new FileMapping();
            m_DataMap.Init(DataMap, DataMapLength);

            m_FormatMap.Write(BitConverter.GetBytes((int)(DataMapLength)), 0, 4);
            m_FormatMap.Write(BitConverter.GetBytes((uint)(m_PosWrite)), 4, 4);

            
        }

        public void InitSession(RemoteService.VideoParameters para)
        {
            m_FormatMap.Write(BitConverter.GetBytes((int)(para.m_Format)), 8, 4);
            m_FormatMap.Write(BitConverter.GetBytes((int)(para.m_FrameRate)), 12, 4);
            m_FormatMap.Write(BitConverter.GetBytes((int)(para.m_PixHeight)), 16, 4);
            m_FormatMap.Write(BitConverter.GetBytes((int)(para.m_PixWidth)), 20, 4);
        }

        public void PushHeader(byte[] header,int length)
        {
            //m_FormatMap.Write(header, 24, length);
        }

        public void PushData(byte[] data,int length)
        {
            m_DataMap.Write(data, m_PosWrite, length);
            m_PosWrite += length;
            m_FormatMap.Write(BitConverter.GetBytes((uint)(m_PosWrite)), 4, 4);
        }

        public void WriteData(byte[] data)
        {
        }

        
    }
}
